home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MPW_TOOL / TOOLS / TOOLS_WI / ICON_8 / MEMMON_F / MINPUT.C < prev    next >
Text File  |  1990-03-02  |  2KB  |  101 lines

  1. /*
  2.  * minput.c: input routines.
  3.  */
  4.  
  5. #include <ctype.h>
  6. #include "memmon.h"
  7.  
  8. static word previous[256];    /* previous length, indexed by input char */
  9.  
  10. /*
  11.  * getcmd(&addr, &len) - get next command, returning key character.
  12.  */
  13. int getcmd(addr, len)
  14. word *addr, *len;
  15.    {
  16.    int c;
  17.    word n;
  18.  
  19.    c = getc(ifile);
  20.    while (isspace(c))
  21.       c = getc(ifile);
  22.    if (c == EOF)
  23.       return 0;
  24.    if (isdigit(c)) {
  25.       n = c - '0';
  26.       while (isdigit(c = getc(ifile)))
  27.          n = 10 * n + c - '0';
  28.       if (c == '+') {
  29.          c = getcmd(addr, len);
  30.          *addr = n;
  31.          }
  32.       else {
  33.          *addr = -1;
  34.          *len = n;
  35.          previous[c] = n;
  36.          }
  37.       } 
  38.    else {
  39.       *addr = -1;
  40.       *len = previous[c];
  41.       }
  42.    return c;
  43.    }
  44.  
  45. /*
  46.  * getshow() - get the color for an mmshow() command.
  47.  *
  48.  *  An mmshow command is followed by two characters "ct";  c is the color
  49.  *  character passed to mmshow(), and t is the type of the item.
  50.  */
  51. word getshow()
  52.    {
  53.    int c, t;
  54.    c = getc(ifile);
  55.    t = getc(ifile);
  56.    switch (c)  {
  57.       case 'b':  return Unmarked + C_Black;
  58.       case 'g':  return Unmarked + C_Grey;
  59.       case 'h':  return Unmarked + C_Blink;
  60.       case 'r':  return Unmarked + blkcolor[t];
  61.       case 'w':  return Unmarked + C_White;
  62.       default:   return Unmarked + C_Blink;
  63.       }
  64.    }
  65.  
  66. /*
  67.  * getregion() - get region information (base, used, length for one region).
  68.  */
  69. novalue getregion(rgn)
  70. struct region *rgn;
  71.    {
  72.    word addr;
  73.  
  74.    getcmd(&addr, &rgn->base);
  75.    getcmd(&addr, &rgn->used);
  76.    getcmd(&addr, &rgn->length);
  77.    }
  78.  
  79. /*
  80.  * rsync() - region synchronization (sanity check).
  81.  *
  82.  *  Rsync reads region information and compares it with what we already know.
  83.  *  A discrepancy indicates a program bug or corrupted data file.
  84.  */
  85. novalue rsync(rgn, label)
  86. struct region *rgn;
  87. char *label;
  88.    {
  89.    struct region r;
  90.  
  91.    getregion(&r);
  92.    if (r.base != rgn->base || r.used != rgn->used || r.length != rgn->length) {
  93.       fprintf(stderr, "%s internal error: out of sync: %s region\n",
  94.          progname, label);
  95.       fprintf(stderr, "expected %ld:%ld/%ld, got %ld:%ld/%ld\n",
  96.          rgn->base, rgn->used, rgn->length, r.base, r.used, r.length);
  97.       exit(ErrorExit);
  98.       }
  99.    }
  100.  
  101.